package com.jiangjiang.eshop.customer.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangjiang.eshop.customer.biz.ReturnGoodsWorksheetBiz;
import com.jiangjiang.eshop.customer.constant.ReturnGoodsWorksheetApproveResult;
import com.jiangjiang.eshop.customer.constant.ReturnGoodsWorksheetStatus;
import com.jiangjiang.eshop.customer.dto.ReturnGoodsQueryPageDTO;
import com.jiangjiang.eshop.customer.dto.ReturnGoodsWorksheetDTO;
import com.jiangjiang.eshop.customer.service.ReturnGoodsWorksheetService;
import com.jiangjiang.eshop.order.dto.OrderInfoDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Jianghaowen
 * @Date 2021/9/9
 * @Description: TODO
 * @Version V1.0
 **/
@Slf4j
@RequestMapping("/return/goods/worksheet")
@RestController
public class ReturnGoodsWorksheetController {
    @Autowired
    private ReturnGoodsWorksheetBiz returnGoodsWorksheetBiz;


    /**
     * 退货工单分页查询
     * @param dto 分页查询条件
     * @return 分页查询结果
     */
    @PostMapping("/queryForPage")
    public Page<ReturnGoodsWorksheetDTO> queryForPage(@RequestBody  ReturnGoodsQueryPageDTO dto){
        try {
            return returnGoodsWorksheetBiz.queryForPage(dto);
        }catch (Exception e){
            log.warn("ReturnGoodsWorksheetController queryForPage error",e);
        }
        return null;
    }


    /**
     * 根据id查询退货工单
     * @param id 退货工单id
     * @return 查询结果
     */
    @GetMapping("/queryById")
    public ReturnGoodsWorksheetDTO queryById(Long id){
        try {
            return returnGoodsWorksheetBiz.queryById(id);
        }catch (Exception e){
            log.warn("ReturnGoodsWorksheetController queryById error",e);
        }
        return null;
    }


    /**
     * 退货工单审核
     *
     * @param id            退货工单id
     * @param approveResult 审核结果
     * @return 处理结果
     */
    @GetMapping("/approve")
    public Boolean approve(@RequestParam("id") Long id, @RequestParam("approveResult") Integer approveResult) {
       try {
           return returnGoodsWorksheetBiz.approve(id, approveResult);
       }catch (Exception e){
           log.warn("ReturnGoodsWorksheetController approve error",e);
       }
        return false;
    }


    /**
     * 确认退货工单已经收到退货商品数据
     *
     * @param id 退货工单id
     * @return 处理结果
     */
    @GetMapping("/confirmReceivedReturnGoods/{id}")
    public Boolean confirmReceivedReturnGoods(@PathVariable("id") Long id) {
        try {
            return returnGoodsWorksheetBiz.confirmReceivedReturnGoods(id);
        }catch (Exception e){
            log.warn("ReturnGoodsWorksheetController confirmReceivedReturnGoods error",e);
        }
        return false;
    }
}
